package src.lanqiao.true_question_G;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.SocketTimeoutException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        int n = MyReader.nextInt();
        int d = MyReader.nextInt();
        int k = MyReader.nextInt();
        node[] a = new node[n];
        for(int i = 0;i < n;i++){
            a[i] = new node();
            a[i].time = MyReader.nextInt();
            a[i].id = MyReader.nextInt();
        }

        Arrays.sort(a, new nodecomparator());

        for (int i = 0; i < n; i++) {
            System.out.println(a[i].time+ " " + a[i].id);
        }
    }
}

class node {
    int id;
    int time;
}

class nodecomparator implements Comparator<node> {
    @Override
    public int compare(node o1, node o2) {
        if (o1.time != o2.time) return o1.time - o2.time;
        else return o1.id - o2.id;
    }
}

class MyReader{
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));//定义字符流
    static StringTokenizer tokenizer = new StringTokenizer("");
    static String nextLine() throws IOException {// 读取下一行字符串
        return reader.readLine();
    }
    static String next() throws IOException {// 读取下一个字符串
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {// 读取下一个int型数值
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {// 读取下一个double型数值
        return Double.parseDouble(next());
    }
}